/**
 * Created by jt on 2017/5/7.
 */
import "./index.less";
import "../../../unit/common/js/bootstrap_js/select2.min.js";
import "../../../unit/common/js/bootstrap_js/jquery.dataTables.js";
import "../../../unit/common/js/bootstrap_js/form-samples.js";

var token = sessionStorage.getItem('token');
if (token == null || token =='') {
    location.href = HOST_FRT+'/logins/login.html';
}
jQuery('.logOut').attr('href','../logins/login.html');
var projId = getArgs().id;

jQuery(function () {
    App.init();

    jQuery.ajax({
        url: HOST_ADDR+'/cpmp/bidProjOff/view/'+projId,
        type: 'get',
        // data: JSON.stringify(data),
        dataType: 'json',
        contentType:"application/json",
        headers: {
            'access_token': token,'login_type':'ums'
        },
        success: function(resp){
            if (!resp.success) {
                alert(resp.msgCod+' '+resp.msgInf);
                return;
            }
            console.log(resp)

            var bidRngTyp='非定向招标';
            var splrs='';
            if (resp.data.bidProjOff.bidRngTyp == 1) {
                bidRngTyp='定向招标';
                for (var i=0;i<resp.data.splrs.length;i++) {
                    // splrs.push(resp.data.splrs[i].splrNam);
                    if(splrs.length){
                        splrs  = splrs + ',' + resp.data.splrs[i].splrNam;
                    }else{
                        splrs = resp.data.splrs[i].splrNam;
                    }
                }
            }
            var currTyp = '';
            var dpstFlg = '';
            var pubPriFlg = '';
            var bidOpenTim = '';
            var bidEndTim = '';
            var projMemo = '';
            var projNbr = '';
            if (resp.data.bidProjOff.currTyp == 'USD') {
                currTyp='美元';
            } else if (resp.data.bidProjOff.currTyp == 'RMB') {
                currTyp='人民币';
            }
            if (resp.data.bidProjOff.dpstFlg == 0) {
                dpstFlg='不需要';
            } else if (resp.data.bidProjOff.dpstFlg == 1) {
                dpstFlg='需要';
            }
            if (resp.data.bidProjOff.pubPriFlg == 0) {
                pubPriFlg='否';
            } else if (resp.data.bidProjOff.pubPriFlg == 1) {
                pubPriFlg='是';
            }
            if (resp.data.bidProjOff.bidOpenTim != 'null'&&resp.data.bidProjOff.bidOpenTim !='') {
                var bidOpenTim = (new Date(resp.data.bidProjOff.bidOpenTim)).Format("yyyy-MM-dd hh:mm:ss");
            }
            if (resp.data.bidProjOff.bidEndTim != 'null'&&resp.data.bidProjOff.bidEndTim !='') {
                var bidEndTim = (new Date(resp.data.bidProjOff.bidEndTim)).Format("yyyy-MM-dd hh:mm:ss");
            }
            if (resp.data.bidProjOff.projMemo != null&&resp.data.bidProjOff.projMemo !='') {
                var projMemo = resp.data.bidProjOff.projMemo;
            }
            if (resp.data.bidProjOff.projNbr != null &&resp.data.bidProjOff.projNbr !='') {
                projNbr=resp.data.bidProjOff.projNbr;
            }

            var matTyp = resp.data.bidProjOff.matTyp;
            if(resp.data.matTypDesc!=null && resp.data.matTypDesc!=''){
                matTyp= resp.data.matTypDesc;
            }
//			console.log(resp);
            jQuery('.basicInfo').append('<div class="portlet-body"><table class="table table-striped table-bordered"><tr><tr>' +
                '<td width="16%">项目名称：</td><td colspan="2">'+resp.data.bidProjOff.projNam+'</td> ' +
                '<td width="16%">项目编号：</td> <td colspan="2">'+projNbr+'</td></tr><tr>' +
                '<td width="16%">招标单位：</td><td colspan="2">'+resp.data.bidProjOff.bidDpt+'</td>' +
                '<td width="16%">招标单位地址：</td><td colspan="2">'+resp.data.bidProjOff.bidDptAddr+'</td></tr><tr>' +
                '<td width="16%">是否需要投标保证金：</td><td colspan="2">'+dpstFlg+'</td>'+
                '<td width="16%">是否需要公开招标价格：</td><td colspan="2">'+pubPriFlg+'</td></tr>'+
                '<tr><td width="16%">投标保证金（元）：</td><td colspan="2">'+resp.data.bidProjOff.bidDpst+'</td>' +
                '<td width="16%">币种：</td><td colspan="2">'+currTyp+'</td></tr>'+
                '<tr><td width="16%">物料品类：</td><td colspan="5" class="matTyp" matTyp="'+resp.data.bidProjOff.matTyp+'">'+matTyp+'</td></tr>' +
                '<tr><td width="16%">投标开标时间：</td><td colspan="2">'+bidOpenTim+'</td>' +
                '<td width="16%">投标截止时间：</td><td colspan="2">'+bidEndTim+'</td></tr><tr>' +
                '<td width="16%">联系人：</td><td colspan="2">'+resp.data.bidProjOff.ctct+'</td>' +
                '<td width="16%">联系电话：</td><td colspan="2">'+resp.data.bidProjOff.ctctTel+'</td></tr><tr>' +
                '<td>招标范围类型：</td><td colspan="2">'+bidRngTyp+'</td>' +
                '<td width="16%">指定招标供应商：</td><td colspan="2">'+splrs+'</td></tr></tr><tr>' +
                '<td>备注信息：</td><td colspan="5">'+projMemo+'</td></tr></tbody></table></div>');


            if (resp.data.bidProjOff.projSts == '-20') {
                var rplMemo = '';
                if (resp.data.bidProjOff.rplMemo!= null && resp.data.bidProjOff.rplMemo !='') {
                    rplMemo = resp.data.bidProjOff.rplMemo;
                }
                jQuery('.basicInfo').after('<div class="portlet box blue"><div class="portlet-title"><div class="caption"><i class="icon-reorder"></i>废标原因</div> ' +
                    '<div class="tools"> <a href="javascript:;" class="collapse"></a></div> </div> ' +
                    '<div class="portlet-body">'+rplMemo+'</div> </div>');
            }

            jQuery('.bidBok').html(resp.data.bidProjOff.bidBok);
            var atches = resp.data.atches;
            if ((atches!=null && atches!='undefined') && atches.length > 0){
                for (var i= 0;i<atches.length;i++) {
                    jQuery('#tab_3').append('<div class="controls atchDiv"><span src="'+atches[i].atchUrl+'">'+atches[i].atchNam+'</span>' +
                        '&emsp;<a target="_blank" href="'+HOST_FILE+atches[i].atchUrl+'">查看</a></div>');
                }
            }
            // getMatType();
        },
        error:function(err){
            console.log(err);
        }
    });
});

// function getMatType(){
//     jQuery.ajax({
//         url: HOST_ADDR+'/cpmp/mat/matSapType',
//         type: 'get',
//         dataType: 'json',
//         contentType:"application/json",
//         headers: {
//             'access_token': token,'login_type':'ums'
//         },
//         success: function(resp){
//             if (!resp.success) {
//                 alert(resp.msgCod+' '+resp.msgInf);
//                 return;
//             }
//             var sourceMatTyp = $(".matTyp").attr("matTyp");
//             for (var i=0;i<resp.data.length;i++) {
//                 if(sourceMatTyp==resp.data[i].matkl2){
//                     $(".matTyp").html(resp.data[i].matkl1name+'('+resp.data[i].matkl2name+')');
//                 }else if(sourceMatTyp==resp.data[i].matkl1){
//                     $(".matTyp").html(resp.data[i].matkl1name);
//                 }
//             }
//         },
//         error:function(err){
//             console.log(err);
//         }
//     });
// }
